#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> st;
        int ans = 0;
        for (int i = 0; i < nums.size(); i++) {
            st.insert(nums[i]);
        }
        for (int i = 0; i < nums.size(); i++) {
            if (st.count(nums[i] - 1)){
                continue;
            }
            int temp = 1, data = nums[i];
            while (st.count(++data)) {
                ++temp;
            }
            ans = max(ans, temp);
        }
        return ans;
    }
};

/**
 * 2023.4.14
*/